package com.zhk.entry.mapper.impl;


import com.zhk.entry.dao.impl.BaseDao;
import com.zhk.entry.mapper.UserMapperService;
import com.zhk.entry.model.User;
import com.zhk.entry.observer.BaseObserver;

import java.sql.Connection;
import java.util.List;


/**
 * 用户操作类
 */

public class UserMapper extends BaseObserver implements UserMapperService<User> {

    private BaseDao baseDao = new BaseDao();

    public UserMapper() {
    }

    public UserMapper(BaseDao baseDao) {
        this.baseDao = baseDao;
    }

    /**
     * 全部查询
     *
     * @return
     */
    @Override
    public List<User> getUserAll() {
        List<User> query = baseDao.getQuery(new User(), null);
        return query;
    }

    /**
     * 根据条件查询
     *
     * @param user
     * @return
     */
    public List<User> getUser(User user, Connection conn) {
        List<User> list = baseDao.getQuery(user, conn);
        return list;
    }

    /**
     * 新增
     *
     * @param user
     * @return
     */
    public String saveUser(User user, Connection conn) {
        int save = baseDao.save(user, conn);
        return save > 0 ? "保存成功" : "保存失败";
    }

    /**
     * 修改
     *
     * @param user
     * @return
     */
    public String updateUser(User user) {
        int update = baseDao.update(user);
        return update > 0 ? "修改成功" : "修改失败";
    }

    /**
     * 删除用户
     *
     * @param user
     * @return
     */
    public String deleteUser(User user) {
        int delete = baseDao.delete(user);
        return delete > 0 ? "删除成功" : "删除失败";
    }

    @Override
    public List getQuery(User user, Connection conn) {
        return null;
    }

    @Override
    public int update(User user) {
        return 0;
    }

    @Override
    public int delete(User user) {
        return 0;
    }

    @Override
    public int save(User use, Connection conn) {
        return 0;
    }


}
